home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Dreamweaver 3 / Configuration / Behaviors / Actions / Set Text / Set Text of Layer.js < prev    next >
Encoding:
Text File  |  1999-12-01  |  4.7 KB  |  145 lines

  1. // Copyright 1999 Macromedia, Inc. All rights reserved.
  2.  
  3. //*************** GLOBALS VARS *****************
  4.  
  5. var helpDoc = MM.HELP_behSetTextOfLayer;
  6.  
  7. //******************* BEHAVIOR FUNCTION **********************
  8.  
  9. //Passed a layer references and a string, replaces layer text.
  10.  
  11. function MM_setTextOfLayer(objName,x,newText) { //v3.0
  12.   if ((obj=MM_findObj(objName))!=null) with (obj)
  13.     if (navigator.appName=='Netscape') {document.write(unescape(newText)); document.close();}
  14.     else innerHTML = unescape(newText);
  15. }
  16.  
  17. document.VERSION_MM_setTextOfLayer = 3.0; //define latest version number for behavior inspector
  18.  
  19. //******************* API **********************
  20.  
  21.  
  22. //Can be used with any tag and any event
  23.  
  24. function canAcceptBehavior(){
  25.   var retVal = false;
  26.   var nameArray = getAllObjectRefs("NS 4.0","document","LAYER");  //get layer names (includes CSS)
  27.   if (nameArray.length > 0) retVal = "onMouseOver,(onMouseOver),onClick,(onClick)"; //default events
  28.   return retVal;
  29. }
  30.  
  31.  
  32.  
  33. //Returns a Javascript function to be inserted in HTML head with script tags.
  34.  
  35. function behaviorFunction(){
  36.   return "MM_findObj,MM_setTextOfLayer";
  37. }
  38.  
  39.  
  40.  
  41. //Returns fn call to insert in HTML tag <TAG... onEvent='thisFn(arg)'>
  42. //Calls escQuotes to find embedded quotes and precede them with \
  43.  
  44. function applyBehavior() {
  45.   var i,index,objNS,newlinePos,msgStr="",retVal="";
  46.   with (document.theForm) {
  47.     index = menu.selectedIndex;
  48.     objNS = escQuotes(document.MM_NS_REFS[index]); //get layer name from list
  49.     msgStr = escExprStr(message.value,true);
  50.   }
  51.   if (objNS.indexOf(REF_UNNAMED) == 0) retVal = MSG_UnnamedLayer;
  52.   else if (msgStr == null) retVal = MSG_BadBraces;
  53.   else {
  54.     objNS = getNameFromRef(objNS);
  55.     updateBehaviorFns("MM_findObj","MM_setTextOfLayer");
  56.     retVal = "MM_setTextOfLayer('"+objNS+"','','"+msgStr+"')";
  57.   }
  58.   return retVal
  59. }
  60.  
  61.  
  62.  
  63. //Passed the function call above, takes prior arguments and reloads the UI.
  64. //Removes any escape characters "\"
  65.  
  66. function inspectBehavior(fnStr){
  67.   var argArray,found,numLayers,i;
  68.   var objNS,objIE,startStr,endStr;
  69.  
  70.   argArray = extractExprStr(fnStr);//get new list of layer,vis pairs
  71.   if (argArray.length == 3) { //3 args
  72.     //set layer obj
  73.     objNS=argArray[0];
  74.     objIE=argArray[1];
  75.     found = false;
  76.     numLayers = document.MM_NS_REFS.length;
  77.     for (i=0; i<numLayers; i++){  //check if layer is in menu
  78.       if (objNS==document.MM_NS_REFS[i] || objNS==getNameFromRef(document.MM_NS_REFS[i])) { //if layer there
  79.         document.theForm.menu.selectedIndex = i;
  80.         found = true;
  81.         break;
  82.       }
  83.     }
  84.     if (!found) alert(errMsg(MSG_LayerNotFound,objNS));
  85.  
  86.     //set text, converting all string expressions to {expression} etc.
  87.     document.theForm.message.value = unescExprStr(argArray[2],true);
  88.   }
  89. }
  90.  
  91.  
  92.  
  93. //Returns a dummy function call to inform Dreamweaver the type of certain behavior
  94. //call arguments. This information is used by DW to fixup behavior args when the
  95. //document is moved or changed.
  96. //
  97. //It is passed an actual function call string generated by applyBehavior(), which
  98. //may have a variable list of arguments, and this should return a matching mask.
  99. //
  100. //The return values are:
  101. //  objName:  argument is simple object name, such as "Layer1"
  102. //  other...: argument is ignored
  103.  
  104. function identifyBehaviorArguments(fnCallStr) {
  105.   var argArray, retVal="", fullObjRef;;
  106.  
  107.   argArray = extractArgs(fnCallStr);
  108.   fullObjRef = (argArray[1].indexOf(".")!=-1);
  109.   if (argArray.length == 4) {
  110.     retVal = (fullObjRef)?"NS4.0ref,IE4.0ref,other" : "objName,other,other";
  111.   }
  112.   return retVal;
  113. }
  114.  
  115. //***************** LOCAL FUNCTIONS  ******************
  116.  
  117.  
  118. //Load up the layers, set the insertion point
  119.  
  120. function initializeUI(){
  121.   var i, niceNameSrcArray, nameArray;
  122.  
  123.     document.MM_NS_REFS = getAllObjectRefs("NS 4.0","document","LAYER"); //store parallel NS refs
  124.     document.MM_IE_REFS = getAllObjectRefs("IE 4.0","document","LAYER"); //store parallel IE refs
  125.     //Search for unreferenceable objects. <DIV id="foo"> is IE only, <LAYER> is NS only.
  126.     //if REF_CANNOT found, return empty string, and use IE refs for nice namelist.
  127.     niceNameSrcArray = document.MM_NS_REFS;
  128.     for (i=0; i<document.MM_NS_REFS.length; i++) {
  129.         if (document.MM_IE_REFS[i].indexOf(REF_CANNOT) == 0) {
  130.             document.MM_IE_REFS[i] = ""; //blank it out
  131.         }
  132.         if (document.MM_NS_REFS[i].indexOf(REF_CANNOT) == 0) {
  133.             document.MM_NS_REFS[i] = ""; //blank it out
  134.             niceNameSrcArray = document.MM_IE_REFS; //use the IE list
  135.         }
  136.     }
  137.     nameArray = niceNames(niceNameSrcArray,TYPE_Layer);  //get layer names (includes CSS)
  138.     with (document.theForm.menu) {
  139.         for (i=0; i<nameArray.length; i++) options[i]=new Option(nameArray[i]); //load menu
  140.         selectedIndex = 0;
  141.     }
  142.   document.theForm.message.focus(); //set focus on textbox
  143.   document.theForm.message.select(); //set insertion point into textbox
  144. }
  145.